<!--
 * @Author: your name
 * @Date: 2021-08-02 01:38:02
 * @LastEditTime: 2021-08-03 21:39:17
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \hrsaas\src\components\lang\index.vue
-->
<template>
  <!-- trigger 点击触发下拉 -->
  <el-dropdown trigger="click" @command="changeLanguage">
    <!-- 这里必须加一个div -->
    <div>
      <svg-icon style="color:#fff;font-size:20px" icon-class="language" />
    </div>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item command="zh" :disabled="'zh'=== $i18n.locale ">中文</el-dropdown-item>
      <el-dropdown-item command="en" :disabled="'en'=== $i18n.locale ">en</el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>
import Cookie from 'js-cookie'
export default {
  methods: {
    changeLanguage(lang) {
      // console.log(this.$i18n.locale)
      console.log(this.$i18n)
      console.log(lang)
      console.log(this.locale)
      Cookie.set('language', lang) // 切换多语言
      // localStorage.setItem('language', lang)
      this.$i18n.locale = lang // 设置给本地的i18n插件
      console.log(this.$i18n.locale)

      this.$message.success('切换多语言成功')
    }
  }
}
</script>

